<?php
namespace app\member\validate;

/**
 * 验证器
 */
use think\Validate;

class Member extends Validate
{
    protected $rule = [
        'user'       => 'require|alphaNum|max:25|min:5', //checkName:user
        'password'   => 'require|max:25|min:5',
        'repassword' => 'require|confirm:password',
        'nickname'   => 'chsAlphaNum|max:25|min:5|unique:user',
        'email'      => 'email|unique:user',
        'captcha'    => 'require|captcha',
    ];

    protected $message = [
        'user.require'         => '名称必须',
        'user.max'             => '名称最多不能超过25个字符',
        'user.alphaNum'        => '名称只能是数字字母',
        'user.min'             => '名称不能少于5',

        'password.require'     => '密码必须',
        'password.max'         => '密码不能超过25',
        'password.min'         => '密码不能少于5',

        'repassword.require'   => '重输入密码必须',
        'repassword.confirm'   => '重输入密码错误',

        'nickname.chsAlphaNum' => '昵称只能是汉字、字母和数字',
        'nickname.max'         => '昵称不能超过15个',
        'nickname.min'         => '昵称不能少于5个',
        'nickname.unique'      => '昵称已经存在',

        'email.email'          => '邮箱格式错误',
        'email.unique'         => '邮箱已经存在',

        'captcha.require'      => '验证码要填写',
        'captcha.captcha'      => '验证码错误',
    ];
    /**
     * 修改用户
     * @return [type] [description]
     */
    public function sceneedit()
    {
        return $this->only(['password', 'nickname', 'email'])
            ->remove('password', 'require');
    }
    /**
     * 用户登录
     * @return [type] [description]
     */
    public function scenelogin()
    {
        return $this->only(['password', 'user', 'captcha']);

    }
    /**
     * 用户注册
     * @return [type] [description]
     */
    public function sceneregister()
    {
        return $this->only(['password', 'repassword', 'user', 'email', 'captcha'])
            ->append('user', 'unique:user,user_name')
            ->append('email', 'unique:user');

    }
    /**
     * 用户找回密码
     * @return [type] [description]
     */
    public function sceneresetpwd()
    {
        return $this->only(['user', 'email', 'captcha'])
            ->remove('email', 'unique');

    }
    /**
     * 用户重置密码
     * @return [type] [description]
     */
    public function scenereset()
    {
        return $this->only(['password', 'repassword', 'captcha']);

    }
}
